﻿using System;
using System.Collections.Generic;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;

namespace SwCSharpAddin1
{
    public class CreateBlockUI
    {
        public IPropertyManagerPage2 swPropertyPage = null;
        CreateBlockUIHandel handler = null;
        ISldWorks iSwApp = null;
        SwAddin userAddin = null;
        IPropertyManagerPageTab ppagetab1 = null;


        #region 注册UI控件信息

        public IPropertyManagerPageSelectionbox selection1;
        public IPropertyManagerPageNumberbox num1;
        public const int selection1ID = 9;
        public const int num1ID = 10;
        
        #endregion

        public CreateBlockUI(SwAddin addin)
        {
            userAddin = addin;
            if(userAddin != null)
            {
                iSwApp = (ISldWorks)userAddin.SwApp;
                CreatePropertyManagerPage();

            }else
            {
                System.Windows.Forms.MessageBox.Show("SwAddin not set.");
            }
        }

        protected void CreatePropertyManagerPage()
        {
            int error = -1;
            int options = (int)swPropertyManagerPageOptions_e.swPropertyManagerOptions_OkayButton |
                (int)swPropertyManagerPageOptions_e.swPropertyManagerOptions_CancelButton;

            handler = new CreateBlockUIHandel(userAddin, this);
            swPropertyPage = (IPropertyManagerPage2)iSwApp.CreatePropertyManagerPage("创建块", options, handler, ref error);
            if(swPropertyPage != null)
            {
                try
                { 
                    AddControls();
                }catch(Exception e)
                {
                    iSwApp.SendMsgToUser2(e.Message, 0, 0);
                }
            }
        }

        protected void AddControls()
        {
            short controlType = -1;
            short align = -1;
            int options = -1;


            //controlType = (int)swPropertyManagerPageControlType_e.swControlType_Selectionbox;
            //align = (int)swPropertyManagerPageControlLeftAlign_e.swControlAlign_LeftEdge;
            //options = (int)swAddControlOptions_e.swControlOptions_Enabled |
            //          (int)swAddControlOptions_e.swControlOptions_Visible;
            //selection1 = swPropertyPage.AddControl(selection1ID, controlType, "选择面上点", align, options, "Displays features selected in main view");
            //if(selection1 != null)
            //{
            //    int[] filter = {(int)swSelectType_e.swSelDATUMPOINTS};
            //    selection1.Height = 20;
            //    selection1.AllowMultipleSelectOfSameEntity = true;
            //    selection1.SetSelectionFilters(filter);
            //}


            controlType = (int)swPropertyManagerPageControlType_e.swControlType_Numberbox;
            align = (int)swPropertyManagerPageControlLeftAlign_e.swControlAlign_LeftEdge;
            options = (int)swAddControlOptions_e.swControlOptions_Enabled |
                      (int)swAddControlOptions_e.swControlOptions_Visible;

            num1 = swPropertyPage.AddControl(num1ID, controlType, "长度", align, options, "输入块长度");
            if(num1 != null)
            {
                num1.DisplayedUnit = 3;
                num1.Value = 100;
            }

        }

        public void Show()
        {
            if(swPropertyPage != null)
            {
                swPropertyPage.Show();
            }
        }
    }
}
